<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>"延川县“三规合一”资源目录"</title>
<link href='./css/bootstrap.min.css' rel='stylesheet' />
<jsp:include page="/commonPages/admin-meta.jsp" flush="true" />
<!-- CSS files -->
<jsp:include page="/commonPages/admin-style.jsp" flush="true" />

<style type="text/css">
body {
	margin: 0;
	overflow: hidden;
	background: #fff;
}

#map {
	position: relative;
	height: 520px;
	border: 1px solid #3473b7;
}

#toolbar {
	position: relative;
	height: 33px;
	padding-top: 5;
}

.win_bg {
	background: #CCC;
	opacity: 0.2;
	filter: alpha(opacity = 20);
	position: absolute;
	left: 0px;
	top: 0px;
	width: 100%;
	height: 100%;
	z-index: 998;
}

.winTitle {
	background: #4192c9;
	height: 20px;
	line-height: 20px;
	position:relative;
}

.winTitle .title_left {
	font-weight: bold;
	color: #FFF;
	padding-left: 5px;
	float: left
}

.winTitle .title_right {
	float: right;
	padding-right: 3px;
}

.winTitle .title_right a {
	color: #FFF;
	text-decoration: none;
	padding-right: 3px;
}

.winTitle .title_right a:hover {
	text-decoration: underline;
	color: #FF0000;
	padding-right: 3px;
}

.transferPreference {
	border: 1px solid #D6E3F1;
	height: 20px;
	margin: 1px 30%;
	padding: 0 12px;
}

.winContent {
	padding: 5px;
	overflow-y: auto;
	height: 550px;
}

.popupWindow {
	right: 680px;
	top: 105px;
	position: absolute;
	width: 1000px;
	height: 600px;
	border: 2px solid #D6E3F1;
	background: #FFF;
	z-index: 9999;
}
.button1{
	background-color:#4192c9;
	border:none;
	color:white;
	pading:15px 32px;
	text-align:center;
	text-decoration:none;
	display:inline-block;
	font-size:16px;
	margin:4px 2px;
	cursor:pointer;
	
	
}
</style>
<script src='./libs/SuperMap.Include.js'></script>
<script src='./js/jquery.js'></script>
 <script type="text/javascript">
           
            var map, local, baseLayer, resultLayer, Spatialanalyst_sample,
            style = {
                strokeColor: "#343434",
                strokeWidth: 0.1,
                pointerEvents: "visiblePainted",
                fill: true,
                fillColor: "#304DBE",
                fillOpacity: 0.8
            };
            var SubMap = new Array();
        	var SubUrl = new Array();
            var featureReasult = new SuperMap.Feature();
            var ReasultData = [];
            var result = null;
            
            var url2 = "http://222.25.188.1:50118/iserver/services/spatialAnalysis-HXSJK/restjsr/spatialanalyst";
            
            var url3 = "http://222.25.188.1:50118/iserver/services/data-jingjin/rest/data/datasources/name/Jingjin/datasets/name/Landuse_R/";
            function init(){
            	
        		var url = "http://222.25.188.1:50118/iserver/services/map-SJK/rest/maps/城镇总体规划拼合图"
        			
        		
        		baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url , {transparent: true, cacheEnabled: true}, {maxResolution:"auto"});
                baseLayer.events.on({"layerInitialized": addLayer});
                resultLayer = new SuperMap.Layer.Vector("叠加结果");
                resultfeature = new SuperMap.Layer.Vector("查找结果");
                vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
                vectorLayer.events.on({"afterfeaturemodified": editFeatureCompleted});
                //vectorLayer.events.on({"layerInitialized": addLayer1});
                modifyFeature = new SuperMap.Control.ModifyFeature(vectorLayer);

                drawPoint = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Point);
                //drawPoint.events.on({"featureadded": selectedFeatureCompleted});

                drawPolygon = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Polygon);
                drawPolygon.events.on({"featureadded": addFeatureCompleted});
                map = new SuperMap.Map("map", {controls: [
    			                                          new SuperMap.Control.LayerSwitcher(),
    			                                          new SuperMap.Control.ScaleLine(),
    			                                          new SuperMap.Control.Zoom(),
    			                                          new SuperMap.Control.Navigation({
    			                                              dragPanOptions: {
    			                                                  enableKinetic: true
    			                                              }}),
    			                                          drawPoint, drawPolygon]
    			                                      });
    			                                      map.addControl(modifyFeature);
    			                                  }
                
          
            
            function editFeatureCompleted(event) {
                modifyFeature.deactivate();
                var editFeatureParameter,
                        editFeatureService,
                        features,
                        attributes,
                        feature = event.feature;

                attributes = feature.attributes;
                var attrNames = [];
                var attrValues = [];
                for(var attr in attributes) {
                    attrNames.push(attr);
                    attrValues.push(attributes[attr]);
                }
                features = {
                    fieldNames:attrNames,
                    fieldValues:attrValues,
                    geometry:event.feature.geometry
                };
                features.geometry.id = feature.fid;
                editFeatureParameter = new SuperMap.REST.EditFeaturesParameters({
                    features: [features],
                    editType: SuperMap.REST.EditType.UPDATE
                });
                editFeatureService = new SuperMap.REST.EditFeaturesService(url2, {
                    eventListeners: {
                        "processCompleted": updateFeaturesProcessCompleted,
                        "processFailed": processFailed
                    }
                });
                editFeatureService.processAsync(editFeatureParameter);
            }
           
            
            function clearAllDeactivate() {
                modifyFeature.deactivate();
                drawPoint.deactivate();
                drawPolygon.deactivate();
            }
            //执行添加地物
            function addFeatureCompleted(drawGeometryArgs) {
                drawPolygon.activate();
                var geometry = drawGeometryArgs.feature.geometry,
                        feature = new SuperMap.Feature.Vector();
                feature.geometry = drawGeometryArgs.feature.geometry,
                        feature.style = style;
                vectorLayer.addFeatures(feature);

                geometry.id = "100000";
                var editFeatureParameter,
                        editFeatureService,
                        features = {
                            fieldNames:["SmID"],
                            fieldValues:["23"],
                            geometry:geometry
                        };
                editFeatureParameter = new SuperMap.REST.EditFeaturesParameters({
                    features: [features],
                    editType: SuperMap.REST.EditType.ADD,
                    returnContent:false
                });
                editFeatureService = new SuperMap.REST.EditFeaturesService(url3, {
                    eventListeners: {
                        "processCompleted": addFeaturesProcessCompleted,
                        "processFailed": processFailed
                    }
                });
                
                //负责将客户端的更新参数传递到服务器
                //alert(editFeatureParameter.features);
                editFeatureService.processAsync(editFeatureParameter);
            }
            
            //添加地物成功
            function addFeaturesProcessCompleted(editFeaturesEventArgs) {
                var addResultIds = editFeaturesEventArgs.result.IDs,
                       resourceInfo = editFeaturesEventArgs.result.resourceInfo;
               //alert(resourceInfo.id);
                if(addResultIds === null && resourceInfo === null) return;

                if((addResultIds && addResultIds.length > 0) || (resourceInfo && resourceInfo.succeed)) {
                    alert("绘制成功!");
                    //vectorLayer.removeAllFeatures();
                    //重新加载图层
                    layer.redraw();
                }else {
                    alert("新增地物失败");
                }
            }
            function processFailed(e) {
                alert(e.error.errorMsg);
            }
            //激活选择地物
            
            function addLayer() {
            	
                map.addLayers([baseLayer,vectorLayer,resultLayer,resultfeature]);
                map.setCenter(new SuperMap.LonLat( 37426871.21 , 4083189.19), 0);
                
            }
            function addLayer1() {
            	//alert("asdjasdhjahs");
                map.addLayer(vectorLayer);
                map.setCenter(new SuperMap.LonLat( 37426871.21 , 4083189.19 ), 0);
                //map.allOverlays = true;
            }
            //控制线检测
            function showAnalysisMap(){
            	   GetMapService();
            	   
                   var resultHtml =
            		
       				
       				"<table  class = 'table table-striped table-bordered table-hover' id ='list_api' >"
            		
       				+"<tr>"+"待检测数据 :"  + '<div id = "sourceDataset"/>'+"</tr>"+"<br/><br/>"
       				+"<tr> "
       				+" 被检测数据 :"  + '<div id = "operateDataset"/>'  +"</tr>"+"<br/><br/>"
       				+"<tr> "
       			    +'<input type = "button" value = "提交" onclick = overlayAnalystProcess()>'
       			 
       				        				
					
       				
       				if (document.getElementById("popupWin")) {
   						$("#popupWin").css("display", "block");
   						//alert("jhgfjgfjsd");
   					} else {
   						$("<div id='popupWin'></div>").addClass("popupWindow").appendTo(
   								$("#toolbar"));	
   					}
				var str = "";
				str += '<div class="winTitle" onMouseDown="startMove(this,event)" onMouseUp="stopMove(this,event)"><span class="title_left">上传项目文件   </span><span class="title_right"><a href="javascript:closeWindow()" title="关闭窗口">关闭</a></span><br style="clear:left"/></div>'; //标题栏

				str += '<div class="winContent" style="overflow-y:auto;height:400px;">';
				str += resultHtml;
				str += '</div>';
				//alert(str);
				$("#popupWin").html(str);
				document.getElementById("popupWin").style.width = "300px";
				document.getElementById("popupWin").style.height = "350px";
            	
				
				
				
            	
            }
            function createSelect(name, str){  
            	
            	
                var _select = document.createElement("select");  
                var firstOption = document.createElement("option");  
                firstOption.value = "-select-";  
                firstOption.text = "-----";  
                _select.appendChild(firstOption); 
                _select.style.width = "150px";
                
                for ( i = 0; i < str.length; i++){  
                    var _option = document.createElement("option");  
                    _option.value = str[i];  
                    _option.text = str[i];  
                    if (name == str[i]){  
                        _option.selected = "true";  
                    }  
                    _select.appendChild(_option);  
                } 
                if(window.addEventListener){
               	 _select.addEventListener('change',selectChange(),false);
               }else{
               	_select.attachEvent('onchange',selectChange());
               }
              
                //_select.onchange = ShowMap2();
                return _select;  
                
            }  
            function selectChange(object){
        		
        	}
        	//从iServer上读取地图数据
            function GetMapService(){
        		
        		var url1 = "http://222.25.188.1:50118/iserver/services/map-HXSJK/rest/maps"
        		var MyMapService = new SuperMap.REST.MapService(url1);
        		MyMapService.events.on({
        			"processCompleted": MapServiceCompleted,
        			"processFailed":MapServiceFailed,
        		});
        		MyMapService.processAsync();
        	
            }
        	
            function MapServiceCompleted(MapServiceEventArgs) {
       		 var result =MapServiceEventArgs.originResult; 
       		 
       		 if (result) {
       			
       						//alert(getMapServiceEventArgs.result.name);
       						for (var j = 0; j < result.length; j++){ 
       							SubMap.push(result[j].name);
       							SubUrl.push(result[j].path);
       						}
       					
       				}
       		 	
       		 document.getElementById("sourceDataset").appendChild(createSelect('', SubMap));
  			 document.getElementById("operateDataset").appendChild(createSelect('', SubMap));
       		
       			
       			}
        function MapServiceFailed(){
        	alert("连接iServer失败！");
        }
       
	
	
            function overlayAnalystProcess() {
            	//var data1 =  $('#sourceDataset option:selected()').text();
            	var data2 = $('#operateDataset option:selected()').text();
            	            	
                resultLayer.removeAllFeatures();
                var overlayServiceByDatasets = new SuperMap.REST.OverlayAnalystService(url2),
                        dsOverlayAnalystParameters = new SuperMap.REST.DatasetOverlayAnalystParameters({
                           
                            sourceDataset: "KZXJC@HXSJK",
                            operateDataset: "JQCYYQKZXPHT@HXSJK",
                            tolerance: 0,
                            operation: SuperMap.REST.OverlayOperationType.INTERSECT
                        });
                
                overlayServiceByDatasets.events.on({"processCompleted": overlayAnalystCompleted, "processFailed": overlayAnalystFailed});
                overlayServiceByDatasets.processAsync(dsOverlayAnalystParameters);
            }
          
            function overlayAnalystCompleted(args) {
                var feature, features = [];
                //alert("ashgdhs");
				if(args.result.recordset.features.length==0)
					{
					
					}
				else{
					ReasultData.splice(0,ReasultData.length);
					for(var i=0;i<args.result.recordset.features.length;i++){
	                	//alert(args.result.recordset.features.fieldNames);                	
	                    feature = args.result.recordset.features[i];
	                    featureReasult = args.result.recordset.features[i];
	                 
	                    feature.style = style;
	                    features.push(feature);
	                    ReasultData.push(featureReasult);
	                    alert(ReasultData[0]);
	                }
	               
	                resultLayer.addFeatures(features);
					
				}
                
               
                
      //弹出框          
                
            }
            
			function ShowResult(){
				
			var resultHtml ="<table  class = 'table table-striped table-bordered table-hover' id ='list_api' >"
       				
       				+"<tr>"
       				+"<th > 序号   "+"</th>" 
       				+"<th>    控制线名称"+"</th>"
       				+"<th>    位置关系 "+"</th>"
       				+"<th>    突破/侵占面积"+"</th>"
       				+"<th>    建议  "+"</th>"
       				+"</tr>";
       			
       				//结果集为空
       				if(ReasultData.length == 0){
       					//alert("asydgasygda");
       					if (document.getElementById("popupWin1")) {
       						$("#popupWin1").css("display", "block");
       						//alert("jhgfjgfjsd");
       					} else {
       						$("<div id='popupWin1'></div>").addClass("popupWindow").appendTo(
       								$("#result"));	
       					}
       					
       					//$("#popupWin").css("display", "none");
       					var str = "";
       					str += '<div class="winTitle" onMouseDown="startMove(this,event)" onMouseUp="stopMove(this,event)"><span class="title_left">jieguoweikong</span><span class="title_right"><a href="javascript:closeWindow()" title="关闭窗口">关闭</a></span><br style="clear:left"/></div>'; //标题栏

       					str += '<div class="winContent" style="overflow-y:auto;height:400px;">';
       					str += resultHtml1;
       					str += '</div>';
       					//alert(str);
       					$("#popupWin1").html(str);
       					document.getElementById("popupWin1").style.width = "600px";
       					document.getElementById("popupWin1").style.height = "432px";
       					
       					
       				}
       				//结果集中含有数据
       				else{
       					for(var i =0;i<ReasultData.length;i++){		
       						if(ReasultData[i].attributes["SmArea"] == 0){
       							 result = "项目范围内没有占用非建设用地 ";
       						}else{
       							result = "项目范围内有："+ReasultData[i].attributes["SmArea"]+"落在非建设用地范围内 ";
       						}
       						
       					  
       		       				resultHtml += "<tr>"
       		       						  +"<td> "+'<a id = "m"  ;href = "javascript:void(0)" ; onclick = "showfeature(\''+ReasultData[i].attributes["SmID"]+'\')";style="line-height: 28px; display: block">'
       		       					+ ReasultData[i].attributes["SmID"]+'</a>' +"</td>"
       		       					      +"<td> "+  ReasultData[i].attributes["NAME"] +"</td>"
       		       					      +"<td> "+  ReasultData[i].attributes["City"] +"</td>" 
       		       				          +"<td> "+  ReasultData[i].attributes["SmArea"] +"</td>"
       		       			              +"<td> "+  result  +"</td>" 
       		       		                  +"</tr>"
       		       					+"</div>"
       					}
       					if (document.getElementById("popupWin1")) {
       						$("#popupWin1").css("display", "block");
       						//alert("jhgfjgfjsd");
       					} else {
       						$("<div id='popupWin1'></div>").addClass("popupWindow").appendTo(
       								$("#result"));	
       					}
       					
       					//$("#popupWin").css("display", "none");
       					var str = "";
       					str += '<div class="winTitle" onMouseDown="startMove(this,event)" onMouseUp="stopMove(this,event)"><span class="title_left">分析结果  </span><span class="title_right"><a href="javascript:closeWindow()" title="关闭窗口">关闭</a></span><br style="clear:left"/></div>'; //标题栏

       					str += '<div class="winContent" style="overflow-y:auto;height:400px;">';
       					str += resultHtml; 
       					
       					str += '</div>';
       					//alert(str);
       					$("#popupWin1").html(str);
       					document.getElementById("popupWin1").style.width = "600px";
       					document.getElementById("popupWin1").style.height = "432px";
       					
       				}
       				
				
			}
			
			
			
			window.closeWindow = function() {
				$("#popupWin").css("display", "none");
			}
			window.startMove = function(o, e) {
				var wb;
				if (SuperMap.Browser.name === "msie" && e.button === 1)
					wb = true;
				else if (e.button === 0)
					wb = true;
				if (wb) {
					var x_pos = parseInt(e.clientX - o.parentNode.offsetLeft);
					var y_pos = parseInt(e.clientY - o.parentNode.offsetTop);
					if (y_pos <= o.offsetHeight) {
						document.documentElement.onmousemove = function(mEvent) {
							var eEvent = (SuperMap.Browser.name === "msie") ? event
									: mEvent;
							o.parentNode.style.left = eEvent.clientX - x_pos + "px";
							o.parentNode.style.top = eEvent.clientY - y_pos + "px";
						}
					}
				}
			}
			window.stopMove = function(o, e) {
			document.documentElement.onmousemove = null;
			}
			
            function overlayAnalystFailed(args) {
                alert(args.error.errorMsg);
               
            }

            function removeResult() {
                resultLayer.removeAllFeatures();
            }
            function showfeature(SmID){
            	
            	resultfeature.removeAllFeatures();
            	
            	
            	for(var i=0;i<resultLayer.features.length;i++){
            		
            		if(resultLayer.features[i].attributes['SmID'] == SmID){
            			
            			var feature1,feature1s = [];	
            			feature1 = resultLayer.features[i];
            			feature1.style ={
            	                strokeColor: "#343434",
            	                strokeWidth: 0.1,
            	                pointerEvents: "visiblePainted",
            	                fill: true,
            	                fillColor: "#304DBE",
            	                fillOpacity: 0.8
            	            };
            			feature1s.push(feature1);
            			//alert(feature1s);
            			resultLayer.removeAllFeatures();
                    	resultfeature.addFeatures(feature1s);
            		}
            		
            	}
            	//alert(resultfeature);
            	
				
			}
            function uploadfile(){
            	var resultHtml =
            		
       				
       				"<table  class = 'table table-striped table-bordered table-hover' id ='list_api' >"
            		
       				+"<tr>"+"项目名称:"  + '<input type="text" name = "ProName" size = "20"/>'+"</tr>"+"<br/><br/>"
       				+"<tr> "
       				+"建设单位:"  + '<input type="text" name = "ProOrg" size = "20"/>'  +"</tr>"+"<br/><br/>"
       				+"<tr> "
       				+"立案类型 :"  + '<input type="text" name = "ProType" size = "20"/>'  +"</tr>"+"<br/><br/>"
       				+"<tr> "
       				+"检测范围   :  "  + '<input type="radio" name = "ProSize" value = "外部导入"/>'+"外部导入"
       				+ '<input type="radio" name = "ProSize" value = "手绘范围 "/>'+"手绘范围 "
       				+"</tr>"+"<br/><br/>"
       				+"<tr> "
       				
       			    + '<input type="file" name = "file1 "/>'  +"</tr>"+"<br/><br/>"
       			    +'<input type = "button" value = "提交" onclick = submit()>'

       				        				
					
       				
       				if (document.getElementById("popupWin")) {
   						$("#popupWin").css("display", "block");
   						//alert("jhgfjgfjsd");
   					} else {
   						$("<div id='popupWin'></div>").addClass("popupWindow").appendTo(
   								$("#toolbar"));	
   					}
				var str = "";
				str += '<div class="winTitle" onMouseDown="startMove(this,event)" onMouseUp="stopMove(this,event)"><span class="title_left">上传项目文件   </span><span class="title_right"><a href="javascript:closeWindow()" title="关闭窗口">关闭</a></span><br style="clear:left"/></div>'; //标题栏

				str += '<div class="winContent" style="overflow-y:auto;height:400px;">';
				str += resultHtml;
				str += '</div>';
				//alert(str);
				$("#popupWin").html(str);
				document.getElementById("popupWin").style.width = "300px";
				document.getElementById("popupWin").style.height = "350px";
            	
				 $(function(){
		            	$(":radio").click(function(){
		            		vectorLayer.removeAllFeatures();
		                    clearAllDeactivate();
		                    drawPolygon.activate();
		            	});
		            });
				
            }
           function submit(){
        	   document.getElementById('uploadfile').submit();
           }
        </script>
    </head>
    <body onload="init()">
    <div id="wrapper">

		<!-- Navigation -->
		<jsp:include page="/commonPages/admin-navigator.jsp" flush="true" />
		<div id="page-wrapper">
		
	
	
        <div id="toolbar">
            <form id = "uploadfile" method = "GET" action="process/loadfile" enctype="multipart/form-data">
            <div id='result' class='container'></div>
            <input type = "button" class = "button1" value = "上传项目文件" onclick = "uploadfile()">
            <input type="button" class ="button1"value="控制线检测" onclick="showAnalysisMap()" />
            <input type="button" class ="button1"value="移除结果" onclick="removeResult()" />
            <input type="button" class ="button1"value="结果展示" onclick="ShowResult()" />
           </form>
            
        </div>
         <div id="map"></div>
         <div id = "selectAnalysis">
         
         </div>
       
	</div>
		<jsp:include page="/commonPages/admin-script.jsp" flush="true" />

	</div>
        
    </body>
</html>
